<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="70px">
            <el-form-item label="下单时间" prop="gsOrderCreateDate">
                <el-date-picker v-model="queryParams.gsOrderCreateDate" value-format="yyyy-MM-dd" type="date"
                    placeholder="请选择下单时间">
                </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="送达时间" prop="gsDeliverGoodsDate">
                <el-date-picker v-model="queryParams.gsDeliverGoodsDate" value-format="yyyy-MM-dd" type="date"
                    placeholder="请选择送达时间">
                </el-date-picker>
            </el-form-item> -->
            <el-form-item label="下单仓库" prop="warehouseName">
                <el-input v-model="queryParams.warehouseName" placeholder="请输入下单仓库" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="产品名称" prop="productName">
                <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="送货单号" prop="sendOrderId">
                <el-input v-model="queryParams.sendOrderId" placeholder="请输入送货单号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="订单状态">
                <el-select v-model="queryParams.gsOrderDetailStatus">
                    <el-option v-for="(item, index) in orderState" :key="index" :label="item.label"
                        :value="item.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="orderList" size="mini">
            <el-table-column type="selection" width="55" align="center" :selectable="checkboxSelect" />
            <el-table-column label="下单仓库" align="center" prop="WAREHOUSENAME" sortable
                :show-overflow-tooltip="columnShow" />
            <el-table-column label="下单时间" align="center" prop="GS_ORDER_CREATE_DATE" :show-overflow-tooltip="columnShow"
                min-width="135" />
            <el-table-column label="送达时间" align="center" prop="GS_DELIVER_GOODS_DATE"
                :show-overflow-tooltip="columnShow" min-width="90" />
            <el-table-column label="产品编码" align="center" prop="GS_CONCENTRICITY_ID" :show-overflow-tooltip="columnShow"
                min-width="120" />
            <el-table-column label="产品名称" align="center" prop="PRODUCTNAME" :show-overflow-tooltip="columnShow" />
            <el-table-column label="型号" align="center" prop="MODEL" :show-overflow-tooltip="columnShow" />
            <el-table-column label="规格" align="center" prop="SPEC" :show-overflow-tooltip="columnShow" />
            <el-table-column label="品牌" align="center" prop="PRODUCT_BRAND" :show-overflow-tooltip="columnShow" />
            <el-table-column label="订货数量" align="center" prop="GS_ORDER_COUNT" :show-overflow-tooltip="columnShow">
                <template slot-scope="scope">
                    <span style="font-size: 15px; font-weight: bold;">{{ scope.row.GS_ORDER_COUNT }}</span>
                </template>
            </el-table-column>
            <el-table-column label="实际送货数量" align="center" prop="actSendCount" width="100">
                <!-- <template slot-scope="scope">
                    <el-input-number v-model="scope.row.actSendCount" :min="1" :max="parseInt(scope.row.GS_ORDER_COUNT)"
                        label="描述文字" size="mini" :disabled="!(scope.row.GS_ORDER_DETAIL_STATUS == 9)"></el-input-number>
                </template> -->
            </el-table-column>

            <el-table-column label="单价" align="center" prop="GS_GOODS_UNITPRICE" :show-overflow-tooltip="columnShow" />
            <el-table-column label="订单状态" align="center" prop="GS_ORDER_DETAIL_STATUS"
                :show-overflow-tooltip="columnShow">
                <template slot-scope="scope">
                    <span v-if="scope.row.GS_ORDER_DETAIL_STATUS == 9">新订单</span>
                    <!-- <span v-else-if="scope.row.GS_ORDER_DETAIL_STATUS == 10" style="color:#409EFF ">已收货</span> -->
                    <span v-else-if="scope.row.GS_ORDER_DETAIL_STATUS == 13">配送中</span>
                    <span v-else-if="scope.row.GS_ORDER_DETAIL_STATUS == 14">已收货</span>
                    <span v-else-if="scope.row.GS_ORDER_DETAIL_STATUS == 10">供应商取消</span>
                    <span v-else-if="scope.row.GS_ORDER_DETAIL_STATUS == 15">仓库拒收</span>
                    <span v-else>其他</span>
                </template>
            </el-table-column>
            <el-table-column label="供应商名称" align="center" prop="PROVIDER_NAME" :show-overflow-tooltip="columnShow" />
            <el-table-column label="实际入库数量" align="center" prop="actReciveCount" :show-overflow-tooltip="columnShow" />
            <el-table-column label="送货单号" align="center" prop="sendOrderId" :show-overflow-tooltip="columnShow"
                width="130" fixed="right">
                <template slot-scope="scope">
                    <span style="cursor: pointer;" @click="printOrder(scope.row.sendOrderId)">{{ scope.row.sendOrderId
                        }}</span>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 打印 -->
        <printComponent ref="printRef" @update="getList" />
    </div>
</template>

<script>
import { listOrder2Api, newListOrderApi, searchSendOrderApi, delOrder, addOrder, updateOrder, createSendOrderApi } from "@/api/system/order";
import printComponent from "./orderProcessingFile/print.vue"


export default {
    name: "orderSearch",
    data() {
        return {
            columnShow: true,
            // 总条数
            total: 0,
            // 订单表格数据
            orderList: [],
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                gsOrderTempid: null,
                warehouseName: null,
                gsOrderCreateDate: null,
                gsDeliverGoodsAddr: null,
                gsConcentricityId: null,
                productName: null,
                model: null,
                spec: null,
                productBrand: null,
                gsOrderCount: null,
                gsGoodsUnitprice: null,
                gsDeliverGoodsDate: null,
                gsOrderDetailStatus: -1,
                notifyResult: null,
                providerCode: null,
                providerName: null,
                actSendCount: null,
                actReciveCount: null,
                sendOrderId: null,

                providerName: JSON.parse(localStorage.getItem('User')).dept ? JSON.parse(localStorage.getItem('User')).dept.deptName : '',
            },

            
            orderState: [
                { label: "全部", value: -1 },
                { label: "未完成", value: 255 },
                { label: "新订单", value: 9 },
                { label: "配送中", value: 13 },
                { label: "已收货", value: 14 },
                { label: "供应商取消", value: 10 },
                { label: "仓库拒收", value: 15 },
            ]
        }
    },

    created() {
        this.getList();
    },

    methods: {
        /** 查询订单列表 */
        getList() {
            this.loading = true;
            listOrder2Api(this.queryParams).then(response => {
                if (response.code == 200) {
                    const _data = response.data;
                    this.orderList = _data.list.map(item => {
                        if (!item.actSendCount) {
                            item.actSendCount = item.GS_ORDER_COUNT;
                        }
                        return item;
                    })
                    this.total = _data.total;
                    this.loading = false;
                } else {
                    this.$message.error(response.msg)
                }
            });
        },

        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },

        // 打印送货单
        printOrder(id) {
            searchSendOrderApi({ sendOrderId: id }).then(res => {
                console.log(res)
                if (res.code == 200) {
                    this.$refs.printRef.printOrder({
                        sendOrderId: id,
                        WAREHOUSENAME: res.data.list[0].WAREHOUSENAME,
                        GS_DELIVER_GOODS_ADDR: res.data.list[0].GS_DELIVER_GOODS_ADDR,
                        GS_DELIVER_GOODS_DATE: res.data.list[0].GS_DELIVER_GOODS_DATE,
                        lists: res.data.list,
                        createdTime: res.data.list[0].GS_ORDER_CREATE_DATE
                    });
                }
            })
        }
    },

    components: {
        printComponent
    }
}
</script>